#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
    pid_t id = fork();
    if(id<0) //创建子进程失败
    {
        exit(1);
    } 
    else if(id == 0) //子进程
    {   
        // char* env[]= { "MYVALUE=1234"};

        // execle("./test",NULL,env);
        char* argv[] = {"ls","-a","-l",NULL};
        execvp("/usr/bin/ls",argv);

        exit(1);
    }
    //父进程等待子进程
    int status;
    waitpid(id,&status,0);  
    int ExitCode = ((status>>8) & 0xFF); //退出状态
    int Signal = (status & 0x7F);   //信号
    printf("ExitCode:%d , Signal:%d\n",ExitCode,Signal);
    sleep(5);
    return 0;
}